package eu.irreality.dai.ui.keyboard;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;

/**
 * A simple keyboard test. Displays keys pressed and released to the screen.
 * Useful for debugging key input, too.
 */
public class KeyTest implements KeyListener
{

    public static void main(String[] args)
    {
	JFrame frame = new JFrame();
	frame.addKeyListener(new KeyTest());
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setVisible(true);
    }

    // a method from the KeyListner interface
    public void keyPressed(KeyEvent e)
    {

	System.out.println(e);
	// System.out.println("Pressed: " + KeyEvent.getKeyText(keyCode));

	// make sure the key isn't processed for anything else
	e.consume();

    }

    // a method from the KeyListner interface
    public void keyReleased(KeyEvent e)
    {
	// int keyCode = e.getKeyCode();
	// System.out.println("Released: " + KeyEvent.getKeyText(keyCode));

	// make sure the key isn't processed for anything else
	e.consume();
    }

    // a method from the KeyListener interface
    public void keyTyped(KeyEvent e)
    {
	// this is called after the key is released - ignore it
	// make sure the key isn't processed for anything else
	e.consume();
    }

}
